package xyf.p11.other.bit;

/**
 * ClassName: J056_TimesOfNumber1
 * Description:
 * Author: xyf
 * Date: 9/9/22 10:15 AM
 * Version: 1.0
 **/
public class J056_TimesOfNumber1
{
    public int[] singleNumbers(int[] nums)
    {
        int tmp = nums[0];
        for (int i = 1; i < nums.length; i++)
        {
            tmp ^= nums[i];
        }

        int one = 1;
        while ((tmp & one) == 0)
        {
            one *= 2;
        }

        int a = 0;
        int b = 0;
        for (int i = 0; i < nums.length; i++)
        {
            if ((one & nums[i]) == 0)
            {
                a ^= nums[i];
            }
            else
            {
                b ^= nums[i];
            }
        }
        return new int[]{a, b};
    }
}